import { list } from "../../../../api/groupBuy";
let app = getApp();
Component({

    lifetimes:{
        attached(){
            this.groupBuyclick();
        },  //在组件实例进入页面节点树时执行
        detached(){

        },  //在组件实例被从页面节点树移除时执行
    },
    /**
     * 组件的属性列表
     */
    properties: {
        info: {
          type: Object,
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        groupBuylist: [
        ],
        pageSize: 10,
        pageNum: 1,
        name: "",
        productLoading:false,
        isBottom:false,
    },

    /**
     * 组件的方法列表
     */
    methods: {
        gotobuy(e){
            console.log(e ,"22222222222222222222")
            let obj={
                productId:e.currentTarget.dataset.data.productId,
                groupId:e.currentTarget.dataset.item.id,
                productType:'group',
                priceBox:e.currentTarget.dataset.data.price,
                groupNum:e.currentTarget.dataset.item.groupNum
              }
            wx.navigateTo({
                url: '/pages/goods/product/groupBuydetails?id=' + e.currentTarget.dataset.data.productId+'&obj='+ JSON.stringify(obj),
            })
        },

        groupBuyclick() {
            list({
                pageNum: this.data.pageNum,
                pageSize: this.data.pageSize,
                mchId: app.globalData.mchId,
                type: 0,
                shopId:app.globalData.shopId,
            }).then((res) => {
                res.data.data.forEach(element => {
                    this.data.groupBuylist.push(element)
                });
                this.setData({
                    groupBuylist: this.data.groupBuylist
                })

                if (res.data.data.length < 10) {
                    this.data.productLoading = true
                    this.setData({
                        productLoading: this.data.productLoading,
                        isBottom: this.data.isBottom,
                    })
                    console.log(this.data.productLoading,"321321")
                }

            });
        },

        onReachBottom:function(){
            if(this.data.productLoading == false){
                wx.showLoading({
                    title: '加载中',
                    })
                    setTimeout(function () {
                    wx.hideLoading()
                    }, 1000)
                this.data.pageNum += 1
                this.data.isBottom = true
                this.groupBuyclick()

            }
        },
    }
})
